package com.wffz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wffz.comm.utils.CommUtils;
import com.wffz.mapper.MobileVerificationCodeMapper;
import com.wffz.po.MobileVerificationCode;
import com.wffz.service.MobileVerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sunlei
 * @className MobileVerificationCodeServiceImpl
 * @Description
 * @date 2022-12-28 15:19
 **/
@Service
public class MobileVerificationCodeServiceImpl implements MobileVerificationCodeService {

    @Autowired
    private MobileVerificationCodeMapper mapper;

    @Override
    public boolean saveMobileVerificationCode(MobileVerificationCode mobileVerificationCode) {
        return mapper.insert(mobileVerificationCode) > 1;
    }

    @Override
    public boolean updateMobileVerificationCode(MobileVerificationCode mobileVerificationCode) {
        return mapper.updateById(mobileVerificationCode) > 1;
    }

    @Override
    public boolean isEfficacious(String mobileNumber, String verificationCode) {
        QueryWrapper<MobileVerificationCode> wrapper = new QueryWrapper<>();
        wrapper.eq("mobile_number", mobileNumber);
        wrapper.eq("verification_code", verificationCode);
        List<MobileVerificationCode> list = mapper.selectList(wrapper);
        return CommUtils.isNotEmptyList(list);
    }
}
